﻿using MySql.Data.MySqlClient;
using SGV.Datos.Interfases;
using SGV.Entidad;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using DapperExtensions;

namespace SGV.Datos.Repositories
{
    public class ArticuloRepository :IArticuloRepository
    {

        private IDbConnection _Db;

        public ArticuloRepository()
        {

        }


        public IList<Articulo> FindAll()
        {
            string query = "SELECT * FROM articulo";

            using (_Db = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQL"].ToString()))
            {

                return _Db.Query<Articulo>(query).ToList();
            }
        }

        public IQueryable<Articulo> Find(Expression<Func<Articulo, bool>> predicate)
        {
            throw new NotImplementedException();
        }

        public Articulo FindById(int id)
        {
            string query = "SELECT * " +
                             "FROM articulo " +                             
                             "WHERE id = " + id;

            Articulo articulo = new Articulo();

            using (_Db = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQL"].ToString()))
            {
                articulo = _Db.Query<Articulo>(query).SingleOrDefault();
            }
            return articulo;
        }

        public int add(Articulo newEntity)
        {
            throw new NotImplementedException();
        }

        public bool remove(int id)
        {
            throw new NotImplementedException();
        }

        public int Modify(Articulo entity)
        {
            throw new NotImplementedException();
        }
    }
}
